from jsonpath import jsonpath

from common.requestHandler import requestHandler
from common.yaml_handler import yaml_data
from config.setting import Configure


class Context:
    token =" "
    token_type = " "


#登录，获取token和menberid
def login():
    req = requestHandler()
    res = req.send("post",Configure.host + '/futureloan/member/login',
                   json=yaml_data['user'],headers = {"X-lemonban-Media-Type":"lemonban.v2"})
    #jsonpath可快捷获得里面内容，$.. 代表里面所有内容中寻找,返回的是列表（如有多个结果，会全部返回）
    token = jsonpath(res,"$..token")[0]
    token_type = jsonpath(res,"$..token_type")[0]
    id = jsonpath(res,"$..id")[0]

    Context.token = token
    Context.token_type = token_type
if __name__ == '__main__':

    login()